﻿using Microsoft.AspNetCore.Authorization;

namespace AuthZ.PolicyBased.Authorizations.AuthorizeAttributes;

public class MinimumAgeAuthorizeAttribute : AuthorizeAttribute
{
    public const string PolicyPrefix = "MinimumAge";

    public MinimumAgeAuthorizeAttribute(int minimumAge) => MinimumAge = minimumAge;

    private int MinimumAge
    {
        get => int.TryParse(Policy?[PolicyPrefix.Length..], out var age) ? age : default;
        set => Policy = $"{PolicyPrefix}{value}";
    }
}